const express = require("express");
const { createServer } = require("http");
const { Server } = require("socket.io");
const path = require('path')

const app = express();

const PORT = 8081

const httpServer = createServer(app);

const io = new Server(httpServer, {
  cors: {
    origin: "*"
  }
});

const socketService = require('./socketService');
const { to16, binaryToHex } = require("./DES/utils");
const { createSecretKey } = require("crypto");

io.on('connection', socketService)

// 为了访问 该服务器下的 index.html
const staticRoot = path.resolve(__dirname, "./public");

app.use(express.static(staticRoot))


httpServer.listen(PORT, () => {
  console.log(`listen port ${PORT}`);
})
// 706f736974697665


// console.log(binaryToHex('0110100101101110011100110111000001101001011100100110010001100100'));

// [{ "number": 921547, "SerialNumber": 4044, "hypothesisKey": "0110100101101110011100110111000001101001011100000011111010010110", "result": "!MXUwVNJ", "verify": true, "spendTime": 0 },
// { "number": 940338, "SerialNumber": 22835, "hypothesisKey": "0110100101101110011100110111000001101001011100100110010001100100", "result": "positive", "verify": true, "spendTime": 0 }]